//
//  main.cpp
//  bubbleSort
//
//  Created by Shane on 17/9/18.
//  Copyright © 2017年 Shane. All rights reserved.
//

#include <iostream>
using namespace std;


void bubbleSort1(int a[], int n){
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n-i-1; ++j) {
            if (a[j] > a[j+1]) {
                std::swap(a[j], a[j+1]);
            }
        }
    }
}

void bubbleSort2(int a[], int n){
    bool flag;
    for (int i = 0; i < n; ++i) {
        flag = true;
        for (int j = 0; j < n-i-1; ++j) {
            if (a[j] > a[j+1]) {
                std::swap(a[j], a[j+1]);
                flag = false;
            }
        }
        if (flag) {
            return ;
        }
    }
}

int main(){
//    int a[] = {1,3,4,7,5,6,8,9,0,10,2};
    int a[] = {0,1,2,3,4,5,6,7,8,9,10};
    int count = sizeof(a)/sizeof(a[0]);
    bubbleSort2(a, count);
    return 0;
}







